
const app = getApp()

Page({
	data: {
		page: 1,
		totalSize: 1,
		imgUrls: [], //轮播图
		indicatorDots: true, //是否显示面板指示点
		autoplay: true, //自动播放
		interval: 5000, //自动切换时间间隔
		duration: 1000, //滑动动画时长
		indicatorColor: "#B5B5B5", //轮播点
		navList: [], //nab列表
		navicon: [{
				'icon': '../../img/nav@3x.png'
			},
			{
				'icon': '../../img/interests@3x.png'
			}, {
				'icon': '../../img/language@3x.png'
			}, {
				'icon': '../../img/early@3x.png'
			},
			{
				'icon': '../../img/professional@3x.png'
			}
		],
		list: [] //所有教师列表
	},
	searchtxt: '', //关键词
	//生命周期
	onLoad: function(options) {
		console.log('options:',options);
		//登陆信息
		var that = this;
		var navList = app.globalData.allselect.courseMain
		this.setData({
			navList: navList
		})
		//banner
		this.getbanner();

		//教师列表
		this.teacher_list()


	},
	onShow: function() {
	},
	//事件处理函数
	course_serchFn: function() { //搜索
		
	},
	onPullDownRefresh: function() {
        this.setData({
        	page: 1,
        	totalSize: 0,
        	list: []
        })
        this.getbanner()
        this.teacher_list(() => {
        	wx.stopPullDownRefresh();
        });
    },
	/**
	 * 页面上拉触底事件的处理函数
	 */
	onReachBottom: function() {
		this.teacher_list();
	},
	teacher_list(callback) {
		let that = this;
		let page = this.data.page;
		let list = this.data.list;
		if(page > 1 && list.length >= this.data.totalSize) {
			return false;
		}

		app.request({
			url: 'teacher/search',
			data: {
				page: page
			},
			sCallback: (res) => {
				if(res.code == 1) {
					list = list.concat(res.data.list);
					page ++;

					that.setData({
						page: page,
						totalSize: res.data.total_size,
						list: list
					})

					callback && callback();
				}
			}
		})
	},
	course_serchFn: function(e) { //搜索输入
		this.searchtxt = e.detail.value
	},
	seachekeyword: function(e) { //搜索
		if (this.searchtxt !== '') {
			wx.navigateTo({
				url: '/pages/searchteacher/index?keyword=' + this.searchtxt,
			})
		}

	},
	//获取banner
	getbanner() { 
		var that = this;
        app.request({
            url: 'ad/index',
            sCallback:(res) => {
                if(res.code == 1) {
                    that.setData({
                        imgUrls: res.data.banner
                    })
                }
            }
        })
	},
	
})
